<template>
  <div class="add-container">
    <div class="add-top">
      <el-page-header @back="goBack"></el-page-header>
    </div>
    <div class="add-main">
      <div class="add-main-top">
        <div class="add-main-tital">
          <p>生成拣货单</p>
        </div>
        <!-- <div>
          <el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-position="left" label-width="0.8rem"
            class="demo-ruleForm">
            <el-row :gutter="20">
              <el-col :span="6">
                <el-form-item label="库房" prop="kf">
                  <el-select v-model="ruleForm.kf" placeholder="请选择">
                    <el-option v-for="(item, index) in $util.getKf()" :key="index" :label="item.name"
                      :value="item.id"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="货位">
                  <el-select v-model="ruleForm.hw" placeholder="请选择">
                    <el-option v-for="(item, index) in $util.getHw()" :key="index" :label="item.name"
                      :value="item.id"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="托盘">
                  <el-select v-model="ruleForm.tp" placeholder="请选择">
                    <el-option v-for="(item, index) in $util.getTp()" :key="index" :label="item.name"
                      :value="item.id"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="物资区分">
                  <el-select v-model="ruleForm.wzqf" placeholder="请选择">
                    <el-option v-for="(item, index) in $util.getWzqf()" :key="index" :label="item.name"
                      :value="item.id"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="主管单位">
                  <el-select v-model="ruleForm.zgdw" placeholder="请选择">
                    <el-option v-for="(item, index) in $util.getZgdw()" :key="index" :label="item.name"
                      :value="item.id"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="入库类型">
                  <el-select v-model="ruleForm.rklx" placeholder="请选择">
                    <el-option v-for="(item, index) in $util.getRklx()" :key="index" :label="item.name"
                      :value="item.id"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="物资分类">
                  <el-select v-model="ruleForm.wzzy" placeholder="请选择">
                    <el-option v-for="(item, index) in $util.getWzzy()" :key="index" :label="item.name"
                      :value="item.id"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </div> -->
      </div>
      <div class="add-main-list" id="mainlist">
        <div class="table-list">
          <ux-grid border show-overflow ref="plxTable" keep-source :height="tabheight" :highlightCurrentRow="false"
            widthResize :rules="ruleslist" @selection-change="selectChange"
            :edit-config="{ trigger: 'click', mode: 'row' }">
            <ux-table-column type="checkbox" width="50" />
            <ux-table-column type="index" title="序号" width="50"></ux-table-column>
            <!-- <ux-table-column field="wzdm" title="物资代码">
            </ux-table-column> -->
            <!-- <ux-table-column field="bmm" title="编目码">

            </ux-table-column> -->
            <ux-table-column field="wzmc" title="物资名称">
            </ux-table-column>
            <ux-table-column field="ggxh" title="规格型号">
            </ux-table-column>
            <ux-table-column field="pch" title="批次号">
            </ux-table-column>
            <ux-table-column field="kcsl" title="库存数量">
            </ux-table-column>
            <ux-table-column field="cksl" title="出库数量" :edit-render="{ autofocus: '.el-input__inner' }">
              <template v-slot:edit="scope">
                <el-input v-model.trim="scope.row.cksl" type="number" :min="1" placeholder="请输入数量" />
              </template>
            </ux-table-column>
            <ux-table-column show-overflow-tooltip field="zldj" title="质量等级">
            </ux-table-column>
            <ux-table-column show-overflow-tooltip field="ccdj" title="储存等级">
            </ux-table-column>
            <ux-table-column show-overflow-tooltip field="scrq" title="生产日期">
            </ux-table-column>
            <ux-table-column field="bzq" title="保质期(月)" :edit-render="{ autofocus: '.el-input__inner' }">

            </ux-table-column>
            <ux-table-column field="gqsj" title="过期时间" :edit-render="{ autofocus: '.el-input__inner' }">

            </ux-table-column>
            <ux-table-column show-overflow-tooltip field="jldw" title="计量单位">
            </ux-table-column>
          </ux-grid>
          <div class="submit-button">
            <el-button type="primary" icon="el-icon-circle-check" @click="submitForm">
              确认
            </el-button>
            <el-button type="primary" icon="el-icon-circle-check" @click="submitForm">
              生成拣货单并拣货确认
            </el-button>
            <el-button type="info" icon="el-icon-delete" @click="goBack">
              取消
            </el-button>
          </div>
        </div>
      </div>
    </div>
    <!-- 导入文件start -->
    <el-dialog :close-on-click-modal="false" :visible.sync="importShow" destroy-on-close title="导入文件" class="m-dialog"
      :append-to-body="true">
      <upload api-url="xqzdDetail/import" @success="uploadSuccess" />
    </el-dialog>
  </div>
</template>
<script>
import Upload from '@/components/Upload/upload'
export default {
  name: 'Page1Add',
  components: { Upload },
  props: {
    gobacktitle: {
      type: String,
      default: '新增',
      required: true,
    },
    datarow: {
      type: Array,
      default: function () {
        return []
      },
    },
  },
  data() {
    return {
      show: true,
      ruleForm: {
        kf: '',
        wzmc: '',
        wzqf: '',
        rkzt: '',
        rklx: '',
        datalist: [],
      },
      rules: {
        kf: [{ required: true, message: '请输入入库单号', trigger: 'blur' }],
      },
      ruleslist: {
        cksl: [{ required: true, message: '请输入出库数量', trigger: 'blur' }],

      },
      tabheight: 500,
      importShow: false,
      rowindex: 0
    }
  },
  created() {

  },
  mounted() {
    this.ruleForm = Object.assign({}, this.datarow[this.rowindex])
    this.$nextTick(() => {
      let height = document.getElementById('mainlist').offsetHeight
      this.tabheight = height - 85
      this.$refs.plxTable.reloadData(this.ruleForm.datalist)
    })
  },
  methods: {
    goBack() {
      this.$parent.groundingshow = false
    },
    submitForm() {
      this.$refs.plxTable.validate(true).then((data) => {
        if (data) {
          return data
        } else {
          if (this.datarow.length > this.rowindex + 1) {
            this.rowindex++
            this.ruleForm = Object.assign({}, this.datarow[this.rowindex])
            return
          }
          this.goBack()
        }
      })
    },
    resetForm(formName) {
      this.$refs[formName].resetFields()
    },
    selectChange(e) { },
    // 添加插入行
    async insertEvent(row) {
      let record = {
        wzdm: '',
        kcsl: null,
        sl: null,
        je: null,
      }
      // 加入行, 表示加入行的row对象，row为空则插入第一行，为-1插入最后一行
      let { row: newRow } = await this.$refs.plxTable.insertRow(record)
      // 激活单元格编辑
      await this.$refs.plxTable.setActiveRow(newRow)
    },
    delwzDetail() {
      this.$refs.plxTable.remove(this.$refs.plxTable.getCheckboxRecords())
    },
    uploadSuccess() {
      this.importShow = false
    },
  },
}
</script>
<style lang="scss" scoped>
.add-container {
  position: fixed;
  left: 0;
  top: .75rem;
  width: 100%;
  height: 100%;
  z-index: 1000;
  background-color: #f6f8f9;
  padding: 0 .2rem 1rem .2rem;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  overflow: hidden;

  .add-top {
    padding: .10rem 0;

    ::v-deep .el-page-header__title {
      font-size: .16rem !important;
    }
  }

  .add-main {
    flex: 1;
    font-weight: bold;
    display: flex;
    flex-direction: column;
    overflow: auto;

    .add-main-top {
      padding: .2rem;
      background: #fff;
      border-radius: .05rem;

      .add-main-tital {
        font-size: .18rem;
        border-left: .10rem solid rgb(121, 189, 255);
        padding-left: .10rem;

        p {
          margin: 0;
        }
      }

      .search-gropu-item {
        margin-top: .20rem;
        width: 90%;
        display: flex;
        // label {
        //   white-space: nowrap;
        //   line-height: 32px;
        //   margin-right: 10px;
        // }
      }

      .el-select {
        width: 100%;
      }
    }

    .add-main-list {
      flex: 1;
      background: #fff;
      box-sizing: border-box;
      padding: 0 20px;

      .list-button-group {
        display: flex;
        flex-direction: row;
        padding-bottom: 20px;

        .button-item {
          padding: 0px 10px;
        }

        .button-item:first-child,
        &:last-child {
          padding: 0px 10px 0 0;
        }
      }
    }

    .el-button {
      font-size: .14rem !important;
    }

    ::v-deep {
      .elx-table--header-wrapper {
        background-color: rgb(233, 243, 255);
      }

      .elx-table {
        font-size: 0.14rem !important;
      }

      .elx-body--column {
        height: .48rem !important;
        line-height: .24rem;
      }

      .elx-header--column {
        background-image: none !important;
        height: .48rem !important;
      }

      .el-date-editor.el-input,
      .el-date-editor.el-input--inner {
        width: 100% !important;
      }

      .el-form-item--small.el-form-item {
        margin-bottom: 0px;
        margin-top: 18px;
      }
    }

    .submit-button {
      margin-top: 20px;
      display: flex;
      justify-content: center;
    }
  }
}
</style>